
package com.cse210.grocerwe.server;

import org.restlet.resource.ServerResource;
import com.cse210.grocerwe.common.*;
import com.cse210.grocerwe.client.*;
import javax.jdo.PersistenceManager;
import org.restlet.resource.Put;
import com.google.appengine.api.datastore.KeyFactory;
import java.util.ArrayList;

public class APIResourceG extends ServerResource implements
APIInterfaceG
{
	  
	PersistenceManager pm;
	
    @Put
    public void purchaseItems(ArrayList<SItem>items)
    {
    	
    	pm = PMF.get().getPersistenceManager();
    	ShoppingItem si;
    	try
    	{
		    for(SItem item : items)
		    {
		    	si = pm.detachCopy(pm.getObjectById(ShoppingItem.class,KeyFactory.stringToKey(item.getKey())));
		    	si.bought(item.getBuyer());
		    	pm.makePersistent(si);
		    }
            
        } finally {
            pm.close();
        }
    }
}
